package com.nmsl.controller;

import com.nmsl.common.core.domain.R;
import com.nmsl.domain.TyPatient;
import com.nmsl.service.TyPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/tyPatient")
public class TyPatientController {
    @Autowired
    private TyPatientService tyPatientService;
    @PutMapping
    public R updateByPrimaryKeySelective(@RequestBody TyPatient record){
        return R.ok(tyPatientService.updateByPrimaryKeySelective(record));
    }

    @GetMapping("/selectByPatientId/{patientId}")
    public R selectByPatientId(@PathVariable Integer patientId){
        return R.ok(tyPatientService.selectByPatientId(patientId));
    }

    @GetMapping("/selectByPrimaryKey2/{patientId}")
    public R selectByPrimaryKey2(@PathVariable Integer patientId){
        return R.ok(tyPatientService.selectByPrimaryKey2(patientId));
    }

    @GetMapping("/waitingCount")
    public R getWaitingCount(@RequestParam Integer patientId) {
        TyPatient currentPatient = tyPatientService.selectByPrimaryKey2(patientId);
        if (currentPatient == null) {
            return R.fail("患者信息未找到");
        }
        int waitingCount = tyPatientService.calculateWaitingCount(currentPatient);

        return R.ok(waitingCount);
    }

    @GetMapping("/getBalance/{patientId}")
    public R getBalance(@PathVariable Integer patientId) {
        return R.ok(tyPatientService.selectBalanceByPatientId(patientId));
    }

    @GetMapping("/getAllPatient")
    public R getAllPatient(){
        return R.ok(tyPatientService.selectAllPatient());
    }

}
